package com.atcc.demo.mapper;

import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Options.FlushCachePolicy;

import com.atcc.demo.dao.Person;
import com.atcc.demo.dao.StudentInfo;

@Mapper
public interface PersonMapper {
	
	//增加一个Person
	@Insert("insert into person(id,name,age,description)value(#{id},#{name},#{age},#{description})")
	@Results({
		@Result(column="id",property="id"),
		@Result(column="name",property="name"),
		@Result(column="age",property="age"),
		@Result(column="description",property="description")
	})
	@Options(flushCache=FlushCachePolicy.TRUE)
	int add(Person person);
	
	//删除一个Person
	@Delete("delect from person where id = #{id}")
	@Results({
		@Result(column="id",property="id"),
		@Result(column="name",property="name"),
		@Result(column="age",property="age"),
		@Result(column="description",property="description")
	})
	int deleteByPrimaryKey(String id);
	
	//更改一个Person
	@Update("update person set name =#{name} age=#{age} where id=#{id}")
	int updateByPrimaryKey(Integer id);
	
	//查询一个Person
	@Select("select *from person where id=#{id}")
	@Results({
		@Result(column="id",property="id"),
		@Result(column="name",property="name"),
		@Result(column="age",property="age"),
		@Result(column="description",property="description")
	})
	@Options(useCache=true,flushCache=FlushCachePolicy.FALSE)
	/*userCache表示查询时缓存查询结果，以提高下次查询速度。
	flushCachePolicy表示查询时不刷新缓存*/
	Person selectById(Integer id);
	
	@Select("select *from person where name=#{name}")
	@Results({
		@Result(column="id",property="id"),
		@Result(column="name",property="name"),
		@Result(column="age",property="age"),
		@Result(column="description",property="description"),
		@Result(column="name",property="classinfo",
		many = @Many(select="com.atcc.demo.mapper.ClassMapper.getClassInfoByName"))
	})
	@Options(useCache=true,flushCache=FlushCachePolicy.FALSE)
	/*userCache表示查询时缓存查询结果，以提高下次查询速度。
	flushCachePolicy表示查询时不刷新缓存*/
	List<StudentInfo> selectByName(String name);
	
	//查询所有的Person
	@Select("select *from person")
	@Results({
	     @Result(column="id",property="id"),
	     @Result(column="name",property="name"),
	     @Result(column="age",property="age"),
	     @Result(column="description",property="description")
	})
	@Options(useCache=true,flushCache=FlushCachePolicy.FALSE)
	List<Person> selectAllPerson();

}
